package com.example.ipcdemo

import android.os.Parcel
import android.os.Parcelable

class Request() :Parcelable {

    //此处不能为伴生对象了,搞不懂,垃圾kt,只能有一个伴生对象
    val GET_INSTANCE = 0
    val GET_METHOD = 1
    //请求类型
    var type :Int = 0

    //请求的是哪个注解修饰的类
    lateinit var serviceId:String
    //请求的方法名
    lateinit var methodName:String
    //方法要执行的参数集合
    lateinit var parameters:List<Parameters>

    constructor(parcel: Parcel) : this() {
        type = parcel.readInt()
        serviceId = parcel.readString()!!
        methodName = parcel.readString()!!
        parameters = parcel.createTypedArrayList(Parameters)!!
    }

    constructor(type: Int, serviceId: String, methodName: String, parameters: List<Parameters>):this() {
        this.type = type
        this.serviceId = serviceId
        this.methodName = methodName
        this.parameters = parameters
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeInt(type)
        parcel.writeString(serviceId)
        parcel.writeString(methodName)
        parcel.writeTypedList(parameters)
    }

    override fun describeContents(): Int {
        return 0
    }

    //伴生对象
    companion object CREATOR : Parcelable.Creator<Request> {

        override fun createFromParcel(parcel: Parcel): Request {
            return Request(parcel)
        }

        override fun newArray(size: Int): Array<Request?> {
            return arrayOfNulls(size)
        }
    }}
}